<template>
  <div id="app">
    <div class="home-art"></div>

    <section class="share-content">
      <header class="page-header">
        <i class="min-logo"></i>
        <div class="share-title">
          <p>上传日期：{{ upDate }}</p>
          <span>{{ clearTime }} 天后过期</span>
        </div>
      </header>

      <article class="share-viwe">

        <div class="share-info">
          <p class="info">{{ list.length }} 个文件， 共 {{ $fn.turnSize(filesize) }}</p>
          <p class="desc" v-if="description">{{ description }} </p>
        </div>

        <div class="view-box">

          <div class="pro" v-for="(item, index) in list" :key="index">
            <div v-if="fileTest(item.type) === 'image'" class="image_waper">
              <img :src=" `${item.url}?p=resize:s,200,200` " :alt="item.fileName" :title="item.fileName">
              <div class="mask">
                <div class="file_waper">{{ item.fileName }}</div>
                <a class="downlaod_btn" :download="item.fileName" :href="`${item.url}?download=true&name=${item.fileName}`">下载</a>
              </div>
            </div>

            <div v-else class="file_waper">
              {{item.fileName}}
              <a class="downlaod_btn" :download="item.fileName" :href="`${item.url}?download=true&name=${item.fileName}`">下载</a>
            </div>
          </div>

        </div>

      </article>

    </section>


  </div>
</template>

<script>
import axios from 'axios';
import { formatDate } from '../mixin/util.js';

export default {
  name: 'Pan',
  data() {
    return {
      list: [],
      upDate: '',
      clearTime: '',
      filesize: 0,
      description: ''
    }
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      axios.post('/getproject', {id: DATA.ID}).then(res => {

        this.list = res.data.fileList;
        this.filesize = res.data.filesize;
        this.upDate = formatDate(new Date(res.data.timestamp), 'yyyy年MM月dd日');
        this.description = res.data.description;

        const D = 24*3600*1000;
        this.clearTime = ((res.data.expireTimestamp - Date.now())/D).toFixed();

      }).catch(err => {

        console.log(err);
      })
    },

    // 检查文件类型
    fileTest(type) {
      if (/image/.test(type)) {
        return 'image'
      }

    }
  }
}
</script>

<style lang="less">
#app {
  min-width: 1000px;
  min-height: 600px;
  overflow: hidden;
}

.home-art {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: cover;
  background-image: url(../assets/homepage_bg.jpg);
  z-index: 0;
}

.share-content {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 680px;
  background: #fff;
  box-shadow: 8px 0 16px rgba(0, 0, 0, 0.2);
}

.min-logo {
  display: inline-block;
  width: 110px;
  height: 38px;
  background: url(../assets/minlogo2x.png) no-repeat center 100%;
  line-height: 1;
  vertical-align: middle;
}

.share-title {
  display: block;
  float: right;
  text-align: right;
  span {
    font-size: 12px;
    color: #999;
  }
}

.share-viwe {
  padding: 20px;
}

.share-info {
  margin-bottom: 20px;
  .info {
    margin-bottom: 8px;
  }
  .desc {
    font-size: 14px;
    color: #888;
  }
}

.view-box {
  margin-right: -10px;
}

.pro {
  position: relative;
  display: inline-block;
  vertical-align: top;
  width: 150px;
  height: 150px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin: 0 10px 10px 0;
  overflow: hidden;

  &:hover {
    .mask {
      transform: scale(1);
      opacity: 1;
    }
  }

  .image_waper {
    position: relative;
    width: 100%;
    height: 100%;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 4px;
    }

    .file_waper {
      background: rgba(0,0,0,.65);
    }
  }

  .file_waper {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 10px;
    font-size: 14px;
    background: rgba(0,0,0,.8);
    border-radius: 4px;
    box-sizing: border-box;
    color: #fff;
  }

  .mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transform: scale(1.1);
    transition: all .2s ease-in-out;
  }

  .downlaod_btn {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 34px;
    line-height: 34px;
    width: 100%;
    text-align: center;
    color: #cacaca;
    font-size: 12px;
    background: #000;
    transition: all .2s ease-in-out;
    &:hover {
      color: #fff;
    }
  }
}
</style>
